import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Scanner;//导包

public class Test {

    /*
    * 按位异或，一个值和0进行按位异或操作所得为该值，相同的两个值进行异或操作，所得为0（甲 按位异或 0 得 甲，甲 按位异或 甲 得 0）。
根据这个性质，由于每个重复元素重复两次，故他们在遍历后将相互抵消，而唯一元素只出现一次，故将得到保留
    * */
    public static int func4(int[] array) {
        int arr = 0;
        for (int a:
             array) {
            arr ^= a;
        }
        return arr;
    }

    public static void main28(String[] args) {
        int[] array = {4,1,2,1,2};
        int ret = func4(array);
        System.out.println(ret);//4
    }
    public static boolean func3(int[] array) {
        int count = 0;
        for (int i = 0; i < array.length; i++) {
            if(array[i] % 2 != 0) {
                count++;
                if(count == 3) {
                    return true;
                }
            }else {
                count = 0;
            }
        }
        return false;
    }
    public static void main27(String[] args) {
        int[] array = {1,2,34,3,4,5,7,23,12};
        boolean ret = func3(array);
        System.out.println(ret);
    }
    public static int func2(int[] array) {
        Arrays.sort(array);//排序
        return array[array.length/2];
    }
    public static void main26(String[] args) {
        int[] array = new int[]{2,2,1,1,1,2,2};
        int ret = func2(array);
        System.out.println(ret);
    }
    public static int[] function(int[] array,int target) {
        int[] tmp = new int[2];//创建一个新数组来接收目标元素的下标
        for (int i = 0; i < array.length; i++) {
            for (int j = i+1; j < array.length; j++) {
                if(array[i] + array[j] == target) {
                    tmp[0] = i;
                    tmp[1] = j;
                    return tmp;
                }
            }
        }
        return null;//找不到返回null
        //return new int[]{-1,-1}
    }
    public static void main25(String[] args) {
        int[] array = new int[] {2,7,11,5};
        int[] ret = function(array,9);
        System.out.println(Arrays.toString(ret));
    }

    public static void func(int[] array) {
        int i = 0;
        int j = array.length-1;
        while ( i < j) {
            while(i < j && array[i] % 2 != 0) {
                i++;
            }
            while(i < j && array[j] % 2 == 0) {
                j--;
            }
            int tmp = array[i];
            array[i] = array[j];
            array[j] = tmp;

        }
    }

    public static void main24(String[] args) {
        int[] array = {12,36,43,39,74,62,117};
        func(array);
        System.out.println(Arrays.toString(array));
    }

    public static void getSum(int [] array) {
        int sum = 0;
        for (int i = 0; i < array.length; i++) {
            sum += array[i];
            System.out.println(sum);
        }
    }
    public static void print(int[] array) {
        for (int i = 0; i < array.length; i++) {
            array[i] = i;
//            System.out.print(array[i]+" ");
        }
    }
    public static void main23(String[] args) {
        int[] array = new int[]{5,8,1,6};
     /*   for (int x:array) {
            System.out.print(x +" ");
        }*/
       /* String ret = Arrays.toString(array);
        System.out.println(ret);*/
//        print(array);
        getSum(array);
        print(array);
    }





    /*pos1 起始位置
    * pos2 中转位置
    * pos3 结束位置
    * */
    public static void hanoi(int n,char pos1,char pos2,char pos3) {
        if(n == 1) {
            move(pos1,pos3);
            return;
        }
        hanoi(n-1,pos1,pos3,pos2);
        move(pos1,pos3);
        hanoi(n-1,pos2,pos1,pos3);
    }
    public static void move(char pos1,char pos2) {
        System.out.print(pos1 + "-->" + pos2 +" ");
    }
    public static void main21(String[] args) {
        hanoi(4,'a','b','c');
    }
    public static int Fib(int n) {
        if(n == 1 || n == 2) {
            return 1;
        }
        return (Fib(n-1) + Fib(n-2));
    }
    public static void main20(String[] args) {
        System.out.println(Fib(5));
    }
    public static int sumEvery(int n) {
        if (n< 10) {
            return n;
        }
        return (n % 10 + sumEvery(n/10));
    }
    public static void main19(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int ret = sumEvery(n);
        System.out.println(ret);
    }

    public static int Fac(int n) {
        if (n == 1) {
            return 1;
        }
        int tmp = n * Fac(n-1);
        return tmp;
    }
    public static void main18(String[] args) {
        int n = 10;
        int sum = 0;
        for (int i = 1; i<= n; i++) {
            sum += Fac(i);
        }
        System.out.println(sum);
    }
    public static void print (int n) {
        if (n < 10) {
            System.out.print(n + " ");
            return;
        }
        print(n / 10);
        System.out.print(n  % 10 + " ");
    }
    public static void main17(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        print(n);
    }
    public static int fac(int n) {
        if (n == 1) {
            return 1;
        }
        int tmp = n * fac(n - 1);
        return tmp;
    }
    public static void main16(String[] args) {
        System.out.println(fac(5));
    }
    public static int getMax(int x, int y) {
        return Math.max(x,y);
    }
    public static double getMax(double x,double y,double z) {
        double Max =Math.max(x,y);
        return Math.max(Max,z);
    }
    public static void main15(String[] args) {
        System.out.println(getMax(4,5));
        System.out.println(getMax(4.0,33.2,5.67));
    }
    public static int getSum(int x,int y) {
        return x + y;
    }
    public static float getSum(float x,float y,float z) {
        return x + y + z;
    }
    public static void main14(String[] args) {
        System.out.println(getSum(2,3));
        System.out.println(getSum(3.4f,1.0f,2.2f));
    }
    public static int fib(int n) {
        if (n == 1 || n == 2) {
            return 1;
        }
        int f1 = 1;
        int f2 = 1;
        int f3 = f1 + f2;
        for (int i = 3; i <= n ; i++) {
            f3 = f1 + f2;
            f1 = f2;
            f2 = f3;
        }
        return f3;
    }
    public static void main13(String[] args) {
        System.out.println(fib(5));
        System.out.println(fib(7));
    }
    public static int max2(int x,int y) {
        return x > y ? x : y;
    }
    public static int max2(int x,int y,int z) {
        int maxNum = max2(x,y);
        int ret = max2(z,maxNum);
        return ret;
    }
    public static void main12(String[] args) {
        int ret = max2(3,7,23);
        System.out.println(ret);
    }
    public static void main11(String[] args) {
        int count = 3;
        Scanner scanner = new Scanner(System.in);
        while (count != 0) {
            System.out.println("请输入你的密码:");
            String password = scanner.nextLine();
            if(password.equals("123456")) {
                System.out.println("登陆成功");
                return;
            }else {
                count--;
                System.out.println("你还有" + count + "次机会");
            }
        }
    }
    public static void main10(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int sc = scanner.nextInt();
        while (sc != 0) {
            System.out.print(sc % 10 + " ");
            sc /= 10;
        }
    }
    public static void main9(String[] args) {
        double sum = 0;
        int ret = 1;
        for (byte i = 1; i < 100; i++) {
            sum += 1.0/i * ret;
            ret = -ret;
        }
        System.out.println(sum);
    }

    public static void main8(String[] args) {
        for (int i = 0; i < 99999; i++) {
            int count = 0;
            int tmp = i;
            while (tmp != 0) {
                count++;
                tmp /= 10;
            }//得到i是几位数
            tmp = i;
            int sum = 0;
            while (tmp != 0) {
                sum += Math.pow(tmp % 10,count);//求幂次方 Math.pow
                tmp /= 10;
            }//求出当前每一位
            if (i == sum) {
                System.out.println(i);
            }
        }
    }

    public static void main7(String[] args) {
        System.out.println("输出且换行");
        System.out.print("输出不换行");
        System.out.printf("%s\n","格式化输出");//类似于C语言
    }

    public static void main6(String[] args) {
        int sum = 0;
        for (int n =1;n<= 5;n++){
            int ret = 1;
            for (int i = 1;i <= n;i++){
                ret *= i;
            }
            sum += ret;
        }
        System.out.println(sum);
    }//for循环求1！+2！+3！+4！+5！的和

    public static void main5(String[] args) {
        int i = 1;
        while (i <= 100) {
            if (i % 15 != 0) {
                i++;
                continue;
            }
            System.out.println(i);
            i++;
        }
    }//找到1-100之间既能被3整除又能被5整除的数字 要求使用continue或break

    public static void main4(String[] args) {
        int i = 1;
        int count = 0;
        while (i <= 100) {
            if (i / 10 == 9) {
                count++;
            }
            if (i % 10 == 9) {
                count++;
            }
            i++;
        }
        System.out.println("1到 100 的所有整数中出现数字9的个数是:"+ count);
    }
    public static void main3(String[] args) {
        int year = 0;
        for(year = 1000;year <= 2000;year++) {
            if (year % 4 ==0 && year % 100 != 0 || year % 400 ==0) {
                System.out.println(year);
            }
        }
    }
    public static void main2(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int x = scanner.nextInt();
            int i = 2;
            while (i <= Math.sqrt(x)) {
                if (x % i == 0) {
                    System.out.println(x + " 不是素数");
                    return;
                }
                i++;
            }
            System.out.println(x+ " 是素数");
    }
    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int x = scanner.nextInt();
        int k = 0;
        while (k < x) {
            int i = 2;
            while (i <= Math.sqrt(k)) {
                if(k % i == 0){
                    System.out.println(k+ " 不是素数");
//                    return;
                }
                i++;
            }
            System.out.println(k+ " 是素数");
            k++;
        }
    }
}
